package com.wangy.sct.common.core;

import java.io.Serializable;

/**
 * ClassName: InvokeResult <br/>
 * Description:  <br/>
 *
 * @author wangyue
 * @version V1.0.0
 * @date 2018/11/5 5:20 PM
 */
public class InvokeResult<T> implements Serializable {

	private String retCode;

	private String retMsg;

	private T retData;

	private String retDataClass;

	public InvokeResult() {
		this.retCode = SctEnum.SUCCESS.getErrCode();
		this.retMsg = SctEnum.SUCCESS.getMessage();
	}

	public InvokeResult(T retData) {
		this.retCode = SctEnum.SUCCESS.getErrCode();
		this.retMsg = SctEnum.SUCCESS.getMessage();
		this.retData = retData;
	}

	/**
	 * @Description:
	 * @param: [description]
	 * @return: com.wangy.sct.common.InvokeResult<T>
	 * @author: wangyue
	 * @Date: 2018/11/16 2:24 PM
	 */
	public InvokeResult<T> setStatus(SctExceptionDescription description) {
		this.retCode = description.getErrCode();
		this.retMsg = description.getMessage();
		return this;
	}

	/**
	 * @Description:
	 * @param: [t]
	 * @return: com.wangy.sct.common.InvokeResult<T>
	 * @author: wangyue
	 * @Date: 2018/11/5 5:28 PM
	 */
	public InvokeResult<T> setData(T t) {
		this.retData = t;
		String className = t.getClass().getName();
		System.out.println("className:" + className);
		this.retDataClass = className;
		return this;
	}

	/**
	 * @Description:
	 * @param: [sctEnum, t]
	 * @return: com.wangy.sct.common.InvokeResult<T>
	 * @author: wangyue
	 * @Date: 2018/11/5 5:28 PM
	 */
	public InvokeResult<T> setData(SctEnum sctEnum, T t) {
		this.retCode = sctEnum.getErrCode();
		this.retMsg = sctEnum.getMessage();
		this.retData = t;
		return this;
	}

	//getter & setter

	public String getRetCode() {
		return retCode;
	}

	public void setRetCode(String retCode) {
		this.retCode = retCode;
	}

	public String getRetMsg() {
		return retMsg;
	}

	public void setRetMsg(String retMsg) {
		this.retMsg = retMsg;
	}

	public T getRetData() {
		return retData;
	}

	public void setRetData(T retData) {
		this.retData = retData;
	}

	public String getRetDataClass() {
		return retDataClass;
	}

	public void setRetDataClass(String retDataClass) {
		this.retDataClass = retDataClass;
	}

	//toString

	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder("{");
		sb.append("\"retCode\":\"")
				.append(retCode).append('\"');
		sb.append(",\"retMsg\":\"")
				.append(retMsg).append('\"');
		sb.append(",\"retData\":")
				.append(retData);
		sb.append('}');
		return sb.toString();
	}

}
